/**
  ******************************************************************************
  * @file    Eeprom.c.c  
  * @author  Dajin Li
  * @version V0.0.1
  * @date    08-08-2015 
  * @brief   This file contains IIC read/write EEPROM  function
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/

#include "stm32f10x.h"
#include "string.h"
#include "global.h"
#include "spi.h"
#include "can_open.h"
#include "var_tbl.h"
//#include "menu.h"
//#include "hourmeter.h"
//#include "CanJ1939.h"

/**
* @brief	reads param from EEPROM.
* @param	none
* @note     none
* @retval   none
*/
void load_parameters_from_ee(void)
{
        s16 i;
        u8 *char_ptr;
        u16 ee_addr;
        u8 length;
        u16 var_attr;

        
        for(i = 0; i < MAX_KWP_DATA_OBJECT_DEF; i++)
        {
            char_ptr = (u8 *) kwp_data_params[i].var;  // read truck type
            ee_addr = kwp_data_params[i].ee_addr;
            var_attr = kwp_data_params[i].attr;
            length = var_attr & VAR_LENGTH_MASK;
            EE_SPI_ReadBuffer(char_ptr, ee_addr, length);
        }

        if((strlen(hardware_id) != 11) && (strlen(hardware_id) != 10))
        {
            strcpy(hardware_id, "00000000000");
        }


        if((strlen(part_number) != 11) && (strlen(part_number) != 10))
        {
            strcpy(part_number, "00000000000");
        }
        

}
/**
* @brief	save param to EEPROM.
* @param	none
* @note     none
* @retval   none
*/
void Save_Parameter(u8 i)
{	
    u8 *char_ptr;
    u16 ee_addr;
    u8 length;
    char_ptr = (u8 *) kwp_data_params[ i].var;
    ee_addr = kwp_data_params[ i].ee_addr;
    length = kwp_data_params[ i].attr & VAR_LENGTH_MASK;
    EE_SPI_WriteBuffer(char_ptr, ee_addr, length);
}
 

